import { axios } from '@/utils/request'

const api = {
  user: '/user/json/list',
  userNav: '/user/info',
  role: '/role/json/list',
  service: '/service',
  permission: '/permission/json/list',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree',
  add: 'role/doCreate'
}

export default api
export function getPermissions2 (token) {
  return axios({
    url: api.permission,
    method: 'get'
  })
}

export function getCurrentUserNav (token) {
  return axios({
    url: api.userNav,
    method: 'get'
  })
}

export function getUserList (parameter) {
  return axios({
    url: api.user,
    method: 'get',
    params: parameter
  })
}

export function getRoleList (parameter) {
  return axios({
    url: '/role/json/list?name=' + parameter,
    method: 'get',
    params: parameter
  })
}

export function getRoleList2 (parameter) {
  return axios({
    url: '/roleTwo/json/list?name=' + parameter,
    method: 'get',
    params: parameter
  })
}

export function getServiceList (parameter) {
  return axios({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions (parameter) {
  return axios({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

export function getOrgTree (parameter) {
  return axios({
    url: api.orgTree,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return axios({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}

export function addRole (parameter) {
  return axios({
    url: '/role/doCreate',
    // url: api.add,
    method: 'post',
    data: parameter
  })
}

export function delRole (parameter) {
  return axios({
    url: '/role/doDelete?roleId=' + parameter,
    method: 'post',
    data: parameter
  })
}

export function assignPermissions (parameter) {
  return axios({
    url: '/upmsRolePermission/json/permission',
    method: 'post',
    data: parameter
  })
}

export function getRoleById (parameter) {
  return axios({
    url: '/role/json/updateByRoleId?roleId=' + parameter,
    method: 'post',
    data: parameter
  })
}

export function updateRole (parameter) {
  return axios({
    url: '/role/doUpdate',
    method: 'post',
    data: parameter
  })
}

export function getCompany (parameter) {
  return axios({
    url: '/organization/json/list',
    method: 'get',
    data: parameter
  })
}
